<template>
	<view class="template-news tn-safe-area-inset-bottom">

		<view class="tn-navbg" :style="{height: vuex_custom_bar_height + 'px'}">
			<!-- 顶部自定义导航 -->
			<tn-nav-bar fixed alpha customBack>
				<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
					<text class='icon tn-icon-left'></text>
					<text class='icon tn-icon-home-capsule-fill'></text>
				</view>
				<view class="tn-flex tn-flex-col-center tn-flex-row-center">
					<text class="tn-text-bold tn-text-xl tn-color-black">内容详情</text>
				</view>
			</tn-nav-bar>
		</view>
		<!-- 内容区域开始 -->
		<view class="tn-margin-top-xs" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
			<view class="nav_title--wrap">
				<view class="nav_title tn-main-gradient-blue" style="padding-left: 10rpx;padding-right: 10rpx;">
					{{articleContent.title || ''}}
				</view>
			</view>

			<view class="news-img" style="padding: 10rpx;">
				<mp-html :content="articleContent.content" />
			</view>

		</view>
		<!-- 内容区域结束 -->

		<!-- 内容为空开始 -->
		<view class="" v-if="articleContent.length==0">
			<view class="" style="padding: 10vh 20rpx;">
				<view class="tn-text-center" style="font-size: 200rpx;padding-top: 30rpx;">
					<text class="tn-icon-empty-page tn-color-gray--light"></text>
				</view>
				<view class="tn-color-gray--disabled tn-text-center tn-text-lg"
					@click="tn('/subpages/help/content?uid=482928805799789437')">
					<tn-button fontColor="#fff" backgroundColor="#01BEFF" height="100rpx" shape="round"
						width="100%">请仔细阅读答题规范</tn-button>
				</view>
			</view>
		</view>
		<!-- 内容为空结束 -->

		<!-- 底部相关阅读风格开始 -->
		<!-- <view class="tn-margin-top tn-padding-top-sm tn-margin-bottom">
      <view class="see">
        <view class="justify-content-item tn-flex tn-flex-col-center">
          <view style="margin-left: 15rpx;margin-right: 6rpx;transform: scale(0.85);">
            <tn-avatar-group :lists="groupAvatarList" size="sm"></tn-avatar-group>
          </view>
          <text class="tn-color-gray">{{groupList.count}}</text>
        </view>
        <view class="justify-content-item tn-color-gray tn-text-center tn-margin-right" style="padding-top: 5rpx;">
          <text class="tn-icon-rocket tn-text-lg"  :style="groupList.is_submit ? 'padding-right: 5rpx;color: red;': ''"></text>
          <text class="tn-padding-right tn-text-df">{{articleContent.read_count || 0}}</text>
          <text class="tn-icon-like-lack tn-text-lg" @click="submitCollection" :style="groupList.is_collection ? 'padding-right: 5rpx;color: red;': ''"></text>
          <text class="tn-text-df" @click="submitCollection">{{articleContent.collect_count || 0}}</text>
        </view>
      </view>
    </view> -->
		<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-sm" style="padding: 20rpx;" v-if="relArticleContent.length > 0">
			<view class="" style="display: flex;justify-content: flex-start;">
				<view v-for="(item, index) in articleContent.keywords"
					class="justify-content-item tn-tag-content__item tn-text-sm tn-text-bold tn-margin-right-xs">
					<text class="tn-tag-content__item--prefix">#</text> {{item}}
				</view>
			</view>
			<view class="justify-content-item tn-color-gray tn-text-center" style="padding-top: 5rpx;">
				<text class="tn-icon-eye tn-padding-right-xs tn-text-lg"></text>
				<text class="tn-padding-right tn-text-df">{{articleContent.read_count}}</text>
				<text class="tn-icon-like-lack tn-padding-right-xs tn-text-lg" @click="submitCollection"
					:style="articleContent.is_collect ? 'color:red;' : ''"></text>
				<text class="tn-text-df" @click="submitCollection"
					:style="articleContent.is_collect ? 'color:red;' : ''">{{articleContent.collect_count}}</text>
			</view>
		</view>
		<!-- 底部相关阅读风格结束 -->

		<!-- 边距间隔 -->
		<view class="tn-strip-bottom" v-if="relArticleContent.length > 0"></view>

		<view class="tn-flex tn-flex-row-between tn-padding-top-sm" v-if="articleContent.lenght > 0">
			<view class="justify-content-item tn-margin tn-text-bold tn-text-xl">
				相关推荐
			</view>
			<view class="justify-content-item tn-margin tn-text-lg tn-color-grey" @click="tn('/homePages/hot')">
				<text class="tn-padding-xs">全部</text>
				<text class="tn-icon-topics"></text>
			</view>
		</view>

		<view class=""  v-if="relArticleContent.lenght > 0">
			<!-- 相关文章开始 -->
			<view class="tn-margin-bottom-lg">
				<block v-for="(item, index) in relArticleContent" :key="index">
					<view class="article-shadow tn-margin" @click="tn('/subpages/exam/collection/detail?uid='+ item.uid +'')">
						<view class="tn-flex">

							<view class="tn-margin-sm tn-padding-top-xs" style="width: 100%;">
								<view class="tn-text-lg tn-text-bold clamp-text-1 tn-text-justify">
									<text class="">{{ item.title }}</text>
								</view>
								<view class="tn-padding-top-xs" style="min-height: 90rpx;">
									<text class="tn-text-df tn-color-gray clamp-text-2 tn-text-justify">
										{{ item.remark }}
									</text>
								</view>
								<view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-sm">
									<view class="justify-content-item tn-tag-content__item tn-margin-right tn-text-sm tn-text-bold">
										<text class="tn-tag-content__item--prefix">#</text> {{ item.category.title }}
									</view>
									<view class="justify-content-item tn-color-gray tn-text-center" style="padding-top: 5rpx;">
										<text class="tn-icon-rocket tn-text-lg" style="padding-right: 5rpx;"></text>
										<text class="tn-padding-right tn-text-df">{{ item.submit }}</text>
										<text class="tn-icon-like-lack tn-text-lg" style="padding-right: 5rpx;"></text>
										<text class="tn-text-df">{{ item.collect }}</text>
									</view>
								</view>
							</view>
							<view class="image-pic tn-margin-sm" :style="'background-image:url(' + item.url + item.path + ')'">
								<view class="image-article">
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
			<!-- 相关文章结束 -->

			<!-- 内容为空开始 -->
			<view class="" v-if="relArticleContent.length == 0">
				<view class="" style="padding: 10vh 20rpx;">
					<view class="tn-text-center" style="font-size: 200rpx;padding-top: 30rpx;">
						<text class="tn-icon-empty-page tn-color-gray--light"></text>
					</view>
					<view class="tn-color-gray--disabled tn-text-center tn-text-lg">暂无相关文档推荐</view>
				</view>
			</view>
			<!-- 内容为空结束 -->
		</view>

	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	import {
		getArticleContent,
		submitArticleCollect
	} from "@/utils/api/article.js"
	export default {
		name: 'TemplateNews',
		mixins: [template_page_mixin],
		data() {
			return {
				groupAvatarList: [],
				groupList: [],
				searchWhere: { // 文章查询条件
					uid: "",
				},
				relArticleContent: [], // 相关文章列表
				articleContent: {}, // 文章内容
			}
		},
		onLoad(params) {
			this.searchWhere.uid = params.uid || ""
			this.getArticleContent()
		},
		methods: {
			// 获取文章内容
			getArticleContent() {
				uni.showLoading({
					title: "努力加载中",
					icon: "none"
				})
				getArticleContent(this.searchWhere).then(res => {
					uni.hideLoading()
					if (res.code == 100) {
						let introduce = res.data.content
						// 替换包着img标签的figure标签，改为能被uniapp理解的div
						introduce = introduce.replace(/\<figure/gi, '<div')
						introduce = introduce.replace(/\<\/figure>/gi, '<\/div>')
						// 为p添加内边距，尽量达到与Web端的预览相同
						introduce = introduce.replace(/\<p/gi, '\<p style=\"padding: 10px 0px;\"')
						//  为字体附上颜色
						introduce = introduce.replace(/\<font color=\"/gi, '\<font style=\"color: ')
						// 删除空的style属性，避免因为和已有的style属性冲突导致不显示
						introduce = introduce.replace(/style=""/gi, '')
						res.data.content = introduce
						this.articleContent = res.data
						return
					}
					this.$func.showToast(res.msg)
				})
			},
			// 文章收藏
			submitCollection() {
				if (this.articleContent.is_collect) {
					this.$func.showToast("你已收藏")
					return
				}
				submitArticleCollect({
					uid: this.searchWhere.uid
				}).then(res => {
					if (res.code == 100) {
						this.articleContent.collect_count = this.articleContent.collect_count + 1
						this.articleContent.is_collect = true
					}
					this.$func.showToast(res.msg)
				})
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	/* 顶部渐变*/
	.tn-navbg {
		background: linear-gradient(-120deg, #F15BB5, #9A5CE5, #01BEFF, #00F5D4);
		/* background: linear-gradient(-120deg,  #9A5CE5, #01BEFF, #00F5D4, #43e97b); */
		/* background: linear-gradient(-120deg,#c471f5, #ec008c, #ff4e50,#f9d423); */
		/* background: linear-gradient(-120deg, #0976ea, #c471f5, #f956b6, #ea7e0a); */
		background-size: 500% 500%;
		animation: gradientBG 15s ease infinite;
		position: fixed;
		top: 0;
		width: 100%;
		z-index: 100;
	}

	@keyframes gradientBG {
		0% {
			background-position: 0% 50%;
		}

		50% {
			background-position: 100% 50%;
		}

		100% {
			background-position: 0% 50%;
		}
	}

	/* 标题 start */
	.nav_title {
		-webkit-background-clip: text;
		color: transparent;
		// text-align: center;

		&--wrap {
			position: relative;
			display: flex;
			height: 120rpx;
			font-size: 42rpx;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			background-image: url(https://tnuiimage.tnkjapp.com/title_bg/title00.png);
			background-size: cover;
		}
	}

	/* 标题 end */

	/* 富文本图示意 start */
	.news-img {
		z-index: -1;
		padding-bottom: 40rpx;

		image {
			width: 100%;
			margin: 20rpx 0;
			// height: 3373rpx;
			// z-index: -1;
		}
	}

	/* 资讯主图 start*/
	.image-article {
		border-radius: 8rpx;
		width: 200rpx;
		height: 200rpx;
		position: relative;
	}

	.image-pic {
		border: 1rpx solid #F8F7F8;
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	.article-shadow {
		border-radius: 15rpx;
		box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
	}

	/* 文字截取*/
	.clamp-text-1 {
		-webkit-line-clamp: 1;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}

	.clamp-text-2 {
		-webkit-line-clamp: 2;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		text-overflow: ellipsis;
		overflow: hidden;
	}



	.image-design {
		padding: 160rpx 0rpx;
		font-size: 40rpx;
		font-weight: 300;
		position: relative;
	}

	.image-pic {
		background-size: cover;
		background-repeat: no-repeat;
		// background-attachment:fixed;
		background-position: top;
		border-radius: 10rpx;
	}

	/* 文章内容 end*/

	/* 间隔线 start*/
	.tn-strip-bottom {
		width: 100%;
		border-bottom: 20rpx solid rgba(241, 241, 241, 0.8);
	}

	/* 间隔线 end*/
</style>